package com.wenhuitec.productlib.ui.adapter.sku;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.wenhuitec.productlib.R;
import com.wenhuitec.productlib.entity.Sku;
import java.util.List;

public class ShowSkuAdapter extends RecyclerView.Adapter<ShowSkuAdapter.ViewHolder> {
    private Context context;
    private List<Sku> list;


    public ShowSkuAdapter(Context context, List<Sku> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_sku_show, viewGroup, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
        viewHolder.skuNameTv.setText(list.get(position).getName());
        viewHolder.skuPriceTv.setText(list.get(position).getPrice());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView skuNameTv;

        TextView skuPriceTv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            skuNameTv = itemView.findViewById(R.id.skuNameTv);
            skuPriceTv = itemView.findViewById(R.id.skuPriceTv);

        }
    }

    public void setList(List<Sku> list) {
        this.list = list;
        notifyDataSetChanged();
    }
}

